#!/bin/bash

echo "输入参数：$@，数量：$#，编译版本号：v$1"

mkclient() {
    go build -ldflags="-X main.version=$1" -o goSipClient src/goSipClient/*.go
    if [ $? -eq 0 ]; then
        echo "编译成功！执行go-selfupdate。"
    else
        echo "编译不成功，退出。"
        exit 1
    fi
    go-selfupdate -o public/goSipClient/ goSipClient $1
    echo "执行go-selfupdate后返回代码：$?，成功！"

    # 初始版本拷贝
    if [ $1 = "1.0.0" ]; then
        CLIENTDIR="/tmp/c"
        echo "初始版本v1.0.0，拷贝新程序到${CLIENTDIR}。"
        if [ ! -d ${CLIENTDIR} ]; then
            echo "没有${CLIENTDIR}目录，生成"
            mkdir ${CLIENTDIR}
        fi
        mv goSipClient ${CLIENTDIR}/goSipClient
    fi
}

if [ $# -gt 0 ]; then
	mkclient $1
else
	echo "mkclient ver"
	exit 1
fi

